import '../../../home/index.dart';
import '../../../home/index.dart';
import '../../index.dart';
import 'package:flutter/cupertino.dart';
class InputsZone extends StatefulWidget {
  final GroupType type;
  InputsZone({this.type});

  @override
  _InputsZoneState createState() => _InputsZoneState();
}

class _InputsZoneState extends State<InputsZone> {
  Map get names {
    var maps = {};
    if (widget.type == GroupType.GroupFive ){
      maps["A"] = "高";
      maps["B"] = "低";
      maps["C"] = "低1";
      maps["D"] = "低2";
    }else if(widget.type == GroupType.Group6){
      maps["A"] = "A";
      maps["B"] = "C";
      maps["C"] = "D";
      maps["D"] = "变";
    }else{
      maps["A"] = "高";
      maps["B"] = "低";
      maps["C"] = "C";
      maps["D"] = "D";
    }
    return maps;
  }
  List<Widget> InputWidgetsContent(InputControllers4 controllers4){
    List<Widget> widgets = List();
    Column inputs = Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SizedBox(height: 20.h),
        Row(
          children: [
            Expanded(
              child: TitleInputWidget(title: this.names["A"],controller: controllers4.controllerA),
            ),
            Expanded(
              child: TitleInputWidget(title: this.names["B"],controller: controllers4.controllerB),
            ),
          ],
        ),
        SizedBox(height: 10.h),
        widget.type == GroupType.Group7 ? Container():
        Row(
          children: [
            Expanded(
                child: TitleInputWidget(title: this.names["C"],controller: controllers4.controllerC)
            ),
            Expanded(
                child: TitleInputWidget(title: this.names["D"],controller: controllers4.controllerD)
            ),
          ],
        ),
        SizedBox(height: 20.h),
      ],
    );
    widgets.add(Expanded(child: inputs));
    if (widget.type == GroupType.Group7){
      var box = Container(
          width: 120.w,
          margin: EdgeInsets.all(14.h),
          decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(8))),
          child: CupertinoButton(
              padding: EdgeInsets.all(0),
              child: Text("交换",style: TextStyle(color: Colors.black54, fontSize: 28.w)),
              onPressed: (){
                var tmpStr = controllers4.controllerA.text;
                controllers4.controllerA.text = controllers4.controllerB.text;
                controllers4.controllerB.text = tmpStr;
              }));
      widgets.add(box);
    }
    var clearBtn = Container(
        width: 120.w,
        margin: EdgeInsets.all(14.h),
        decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(8))),
        child: CupertinoButton(
            padding: EdgeInsets.all(0),
            child: Text("清除",style: TextStyle(color: Colors.black54, fontSize: 28.w)),
            onPressed: (){
              controllers4.controllerA.text = '';
              controllers4.controllerB.text = '';
              controllers4.controllerC.text = '';
              controllers4.controllerD.text = '';
              controllers4.controllerDD.text = '';
            }));

    widgets.add(clearBtn);
    return widgets;
  }
  @override
  Widget build(BuildContext context) {
    InputControllers4 model = Provider.of<InputControllers4>(context);
    model.oberseverControllersChange(GroupType.Group6);
    return Container(
      decoration: BoxDecoration(
          color: Colors.lightBlue,
          borderRadius: BorderRadius.all(Radius.circular(4)),
          boxShadow: [BoxShadow(color: Colors.black45,offset: Offset(0, 0),blurRadius: 4.0,)]
      ),
      width: MediaQuery.of(context).size.width - 20.w,
      child: Row(
        children: InputWidgetsContent(model),
      ),
    );
  }
}

class TitleInputWidget extends StatefulWidget {
  final TextEditingController controller;
  final String title;
  TitleInputWidget({this.controller,this.title});
  @override
  _TitleInputWidgetState createState() => _TitleInputWidgetState();
}

class _TitleInputWidgetState extends State<TitleInputWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: [
          Container(
            width: 88.w,
            alignment: Alignment.center,
            child: Text(widget.title,style: TextStyle(color: Colors.white,fontWeight: FontWeight.w700,fontSize: 30.w),),
          ),
          Expanded(
              child:Container(
                height: 54.h,
                alignment: Alignment.center,
                child: CupertinoTextField(
                  controller: widget.controller !=null ?  widget.controller : TextEditingController(),
                  keyboardType: TextInputType.number,
                  style: TextStyle(fontSize: 42.w),
                  textAlign: TextAlign.start,
                  padding: EdgeInsets.fromLTRB(16.w,0,0,0),
                ),
              )
          ),
        ],
      ),
    );
  }
}